/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "./BasicCurve.h"

/**************************************************************
* Constructors                                                *
***************************************************************/
BasicCurve::BasicCurve() {

}
    
/**************************************************************
* Operators                                                   *
***************************************************************/


/**************************************************************
* Other helpful functions                                     *
***************************************************************/
/*virtual*/ cVoid BasicCurve::Render(Renderer& renderer, Matrix4D& matrix, ProjectionPlane& plane, cWinColor color) {
	cInt iHalfWidth = renderer.GetWidth() >> 1, iHalfHeight = renderer.GetHeight() >> 1;
	cInt iNrOfPoints = mPoints.GetSize();
	Point4D *points = new Point4D[iNrOfPoints];
	
	Point4D a, b;
	for (cInt i = 0; i < iNrOfPoints; i++) {
		points[i] = matrix * mPoints[i];
	}
	for (cInt i = 0; i < iNrOfPoints - 1; i++) {
		a = points[i];
		b = points[i + 1];
		if (plane.Clip(a, b)) {
			a.mX = (a.mX / a.mW) + iHalfWidth; 
			a.mY = (a.mY / -a.mW) + iHalfHeight;
			b.mX = (b.mX / b.mW) + iHalfWidth; 
			b.mY = (b.mY / -b.mW) + iHalfHeight;
			renderer.DrawROPLine(a, b, color);
		}
	}
	delete [] points;
}

/*virtual*/ Point4D BasicCurve::GetCurvePoint(cInt iIndex) {
	return mPoints[iIndex];
}

/*virtual*/ cInt BasicCurve::GetCurveNrOfPoints() {
	return mPoints.GetSize();
}

/*virtual*/ cVoid BasicCurve::AddPoint(const Point4D& point) {
	mPoints.Add(point);
}